package com.niit.dao.impl;

import com.niit.dao.ICarouselDao;
import com.niit.domain.Carousel;
import com.niit.utils.DBHelper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CarouselDaoImpl implements ICarouselDao {
    @Override
    public List<Carousel> queryCarousel(Integer page) {
        //创建list集合
        List<Carousel> list=new ArrayList<>();
        //编写sql语句
        String sql="select * from sh_carousel order by sort limit ?";
        System.out.println(sql);
        //将数据存放到结果集
        ResultSet rs= DBHelper.executeQuery(sql,page);
        while (true){
            try {
                if (!rs.next()) break;
            } catch (SQLException e) {
                e.printStackTrace();
            }
            Carousel carousel = null;
            try {
                carousel = new Carousel(rs.getInt(1),rs.getString(2),rs.getInt(3));
            } catch (SQLException e) {
                e.printStackTrace();
            }
            list.add(carousel);
        }
        return list;
    }
}
